home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / HIERSV.PAK / SVRITEM.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  142 lines

  1. // svrdoc.h : interface of the CServerNode class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #ifndef _SVRITEM_H
  14. #define _SVRITEM_H
  15.  
  16. #define CX_MARGIN   8
  17. #define CY_MARGIN   4
  18.  
  19. #define CX_INDENT   12
  20. #define CX_BACKDENT 5
  21. #define CY_SEPARATOR 4
  22.  
  23. class CServerDoc;
  24. class CServerItem;
  25.  
  26. // in this example a CServerNode represents a node in a graph
  27. class CServerNode : public CObject
  28. {
  29.     DECLARE_SERIAL(CServerNode);
  30.  
  31. // Constructors
  32. public:
  33.     CServerNode(CServerDoc* pServerDoc = NULL);
  34.     static CServerNode* CreateRootNode(CServerDoc* pDoc);
  35.     void InitRootNode();
  36.  
  37.     // create from parent node
  38.     CServerNode* CreateChildNode(LPCTSTR lpszDescription);
  39.     CServerNode* PromptNewChildNode();  // create with user interface
  40.  
  41. // Attributes
  42.     CString     m_strDescription;       // node description/caption
  43.     CString     m_strLinkKey;           // link node if different from caption
  44.     CServerItem* m_pServerItem;         // pointer to active item (may be NULL)
  45.     CObList     m_listChild;            // list of children
  46.     BOOL        m_bHideChildren;
  47.     CServerDoc* m_pDocument;            // back pointer to document
  48.  
  49.     enum EShape
  50.     {
  51.         shapeRect,
  52.         shapeRound,
  53.         shapeOval,
  54.         shapeMax
  55.     } m_shape;      // shape to draw
  56.  
  57.     CServerDoc* GetDocument() const // return type-safe container
  58.         { return (CServerDoc*)m_pDocument; }
  59.     BOOL HasChildren() const
  60.         { return m_listChild.GetCount() != 0; }
  61.     BOOL IsChild(const CServerNode* pPotentialChild) const;
  62.     // for popup context sensitive menus (in IDR_POPUPS)
  63.     int GetPopupMenuIndex()
  64.         { return 0; }   // 0 for simple menu
  65.     CServerNode* GetNext(CServerNode *pItem, BOOL bInit = TRUE);
  66.     CServerNode* GetPrev(CServerNode *pItem, BOOL bInit = TRUE);
  67.     const CString& GetItemName();
  68.     void UpdateItemName();
  69.  
  70. // Operations
  71.     // bounding rect helpers
  72.     void CalcNodeSize(CDC* pDC, CSize& sizeNode);
  73.  
  74.     // drawing helpers
  75.     BOOL Draw(CDC* pDC, CPoint pt, BOOL bSelected, CSize sizeNode);
  76.     BOOL FindAndDelete(CServerNode *pItem);
  77.         // find pItem, remove it and all of its children
  78.     void DeleteChildNodes();    // remove all child nodes from a given node
  79.     CServerNode* FindNode(LPCTSTR pszItemName);
  80.  
  81.     // recursive bounding rect and drawing helpers
  82.     void CalcBounding(CDC* pDC, CPoint& ptStart, CSize& sizeMax);
  83.     int DrawTree(CDC* pDC, CPoint ptStart, CServerNode* pItemSel);
  84.  
  85.     // simple UI helpers
  86.     BOOL PromptChangeNode();
  87.  
  88.     virtual void Serialize(CArchive& ar);        // for native data
  89.  
  90. // Implementation
  91. public:
  92.     ~CServerNode();
  93.  
  94. protected:
  95.     void SaveAsText(CArchive& ar, int nLevel);
  96.  
  97.     friend class CServerItem;   // CServerItem is an extension of a CServerNode
  98. };
  99.  
  100.  
  101. // CServerItem represents the OLE glue to a CServerNode.  Such items
  102. //  are only allocated as necessary.
  103.  
  104. class CServerItem : public COleServerItem
  105. {
  106. // Constructors
  107. public:
  108.     CServerItem(CServerDoc* pDoc, CServerNode* pNode);
  109.  
  110. // Attributes
  111.     CServerNode* m_pServerNode;     // back pointer to node (may be NULL)
  112.  
  113.     CServerDoc* GetDocument() const // return type-safe container
  114.         { return (CServerDoc*)COleServerItem::GetDocument(); }
  115.  
  116. // Overridables
  117. protected:
  118.     virtual void Serialize(CArchive& ar);   // called for clipboard save
  119.  
  120.     virtual BOOL OnDraw(CDC* pDC, CSize& rSize);
  121.     virtual BOOL OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize);
  122.     virtual void OnOpen();      // select the node when a link is shown
  123.  
  124.     virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  125.     virtual COleDataSource* OnGetClipboardData(BOOL bIncludeLink,
  126.         LPPOINT pptOffset, LPSIZE pSize);
  127.  
  128. // Implementation
  129. public:
  130.     ~CServerItem();
  131.  
  132. protected:
  133.     // GetNativeClipboardData called by overrided OnGetClipboardData
  134.     void GetNativeClipboardData(COleDataSource *pDataSource);
  135.  
  136.     friend class CServerNode;   // CServerNode is an extension of CServerItem
  137. };
  138.  
  139. #endif
  140.  
  141. /////////////////////////////////////////////////////////////////////////////
  142.